package com.glsc.ngateway.common.base.repo.mysql.gateway.platform.it;


import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItCloudDevice;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItServerDevice;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface ItCloudDeviceRepo extends JpaRepository<ItCloudDevice, String> {

    ItCloudDevice findByDevId(String devId);

    @Query(value = "select m from ItVirtualDevice m where 1=1 and (:userid is null OR m.userId = :userid) and m.mark='1' order by m.insertTime desc")
    Page<ItCloudDevice> getCloudDeviceByUser(Pageable pageable, String userid);


    @Query(value = "select m from ItCloudDevice m where 1=1 and m.mark=1 " +
            "and (:cloudId is null OR m.cloudId = :cloudId )  " +
            "and (:cloudStyle is null OR m.cloudStyle = :cloudStyle )  " +
            "and (:cloudArea is null OR m.cloudArea = :cloudArea )  " +
            "and (:userId is null OR m.userId = :userId)  " +
            "and (:application is null OR m.application LIKE CONCAT('%',:application,'%'))  " +
            "order by m.insertTime desc ")
    Page<ItCloudDevice> searchCloudDevice(Pageable pageable, String cloudId, String cloudStyle, Integer cloudArea, String userId, String application);

    @Query(value = "select m from ItCloudDevice m where 1=1 " +
            "and (m.businessName = :systemClassNo " +
            "and m.userId = :systemUserId " +
            "and m.mark = 1 " +
            "and m.devId != :devId) ")
    List<ItCloudDevice> queryBySystemClassNoAndUserId(String systemClassNo, String systemUserId, String devId);

    @Query(value = "select m from ItCloudDevice m where 1=1 " +
            "and (m.businessName = :systemClassNo " +
            "and m.userId = :systemUserId " +
            "and m.mark = 1)")
    List<ItCloudDevice> queryBySystemClassNoAndUserIdWhitOutId(String systemClassNo, String systemUserId);
}
